﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core.Native.InternetExplorer;
using WatiN.Core;
using WatiN.Core.Native.Mozilla;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using DeathByCaptcha;
using System.Windows.Forms;
using System.Drawing;
using WatiN.Core.UtilityClasses;
using WatiN.Core.DialogHandlers;
using mshtml;
using System.Drawing.Imaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core.DialogHandlers;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using SHDocVw;
using WatiN.Core;
using mshtml;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using WatiN.Core.Logging;
using WatiN.Core.Native.Windows;


namespace WindowsFormsApplication4
{
    public class OKDialogHandler : WatiN.Core.DialogHandlers.BaseDialogHandler
    {
        public override bool HandleDialog(Window window)
        {
            var button = GetOKButton(window);
            button.Click();
            return false;
        }

        public override bool CanHandleDialog(Window window)
        {
            return GetOKButton(window) != null;
        }

        private WatiN.Core.Native.Windows.WinButton GetOKButton(Window window)
        {
            var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WatiN.Core.Native.Windows.WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
            if (windowButton == null)
                return null;
            else
                return new WatiN.Core.Native.Windows.WinButton(windowButton.Hwnd);
        }
    }

}
